<?php
/**
 * Created by PhpStorm.
 * User: ewen
 * Date: 5/6/21
 * Time: 1:19 PM
 */

namespace app\common\model;


class FundAmountItem extends Common
{
    //  期权交易流水表

    protected $table = 'fund.fund_amount_item';

    /**
     * 获取期权交易总额
     * @param $userID
     * @return float|int
     */
    public static function getSumData($userID)
    {
        $userID = FundAccount::getFundUserID($userID);
        if (!$userID) return 0;

        $plus = self::where([
            'uid' => $userID,
            'status' => 1,
            'symbol' => 'USDT',
            'amount_type' => ['in', [2001, 2002]],
            'amount' => ['>', 0]
        ])->sum('amount');

        $minus = self::where([
            'uid' => $userID,
            'status' => 1,
            'symbol' => 'USDT',
            'amount_type' => ['in', [2001, 2002]],
            'amount' => ['<', 0]
        ])->sum('amount');
        $minus = abs($minus);

        return $plus + $minus;
    }

}